package cn.vin.storm;

import com.aliyun.odps.Odps;
import com.aliyun.odps.Project;
import com.aliyun.odps.Projects;
import com.aliyun.odps.account.Account;
import com.aliyun.odps.account.AliyunAccount;

import java.util.Iterator;

public class Demo {
    public static void main(String[] args) throws Exception {
        Account account = new AliyunAccount("oxBNkNv3SLinxGZX","7SrY00k1tjBuB78fox1HoKHx3kXClO");
        Odps odps = new Odps(account);
        String odpsUrl = "http://service.cn.maxcompute.aliyun.com/api";
//        String odpsUrl = "http://dt.cn-hangzhou.maxcompute.aliyun.com";
        odps.setEndpoint(odpsUrl);
        Projects projects = odps.projects();

        Iterable<Project> iterable = projects.iterable("ap0104o0s@aliyun.com");
        Iterator<Project> iterator = iterable.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next().getName());
        }
        /*Tables tables = odps.tables();
        for(Table t : tables) {
            System.out.println(t.getName());
        }
        Instance instance = SQLTask.run(odps, "select 'Hello world';");
        instance.waitForSuccess();
        List<Record> result = SQLTask.getResult(instance);
        result.forEach(o -> System.out.println(o.getString(0)));*/
        /*TableTunnel tableTunnel = new TableTunnel(odps);
        TableTunnel.UploadSession uploadSession = tableTunnel.createUploadSession("kariquaaaaaaa", "tbl1");
        Record record = uploadSession.newRecord();
        record.setBigint("id",1L);
        record.setString("name","Tom");
        RecordWriter recordWriter = uploadSession.openRecordWriter(0);
        recordWriter.write(record);
        recordWriter.close();
        uploadSession.commit(new Long[]{0L});*/
    }
}
